package cc.customer.web.bigEpResoure;

import cc.customer.bigEmport.damain.BigEmp;
import cc.customer.bigEmport.damain.IpRecords;
import cc.customer.bigEmport.services.BigEmpIrecords;
import cc.customer.bigEmport.services.BigEmpServices;
import cc.customer.common.domain.QueryRequest;
import cc.customer.common.domain.ResponseBo;
import cc.customer.common.utils.FileUtils;
import cc.customer.system.domain.MyUser;
import cc.customer.web.sys.controller.base.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value ="bigScreen" )
public class BigScreenController extends BaseController {
   private Logger logger = LoggerFactory.getLogger(BigScreenController.class);

   @Autowired
   private BigEmpIrecords bigEmpIrecords;
   @Autowired
   private BigEmpServices bigEmpServices;

   /**主页面**/
   @RequestMapping(value = "bigIndex")
   public String getIndex(){
      return "customer/BigEpResource/bigScreen/bigScreen_index";
   }
   /**导出详情的页面**/
   @RequestMapping(value = "/exportDetail")
   public String  getExportDetail(){
      return "customer/BigEpResource/bigScreen/bigscreen_edetail";
   }
   /**导入详情的页面**/
   @RequestMapping(value = "/importDetail")
   public String  importDetail(){
      return "customer/BigEpResource/bigScreen/bigscreen_idetail";
   }

   /**
    * 获取大资源所有的导出记录 分页
    * **/
   @RequestMapping(value = "/exportRecord")
   @ResponseBody
   public Map<String,Object> getallExportRecords(IpRecords records, QueryRequest queryRequest){
      return super.selectByPageNumSize(queryRequest,() -> this.bigEmpIrecords.getIpRecords(records));
   }

   /**
    * 获取AI资源所有的导出记录 分页
    * **/
   @RequestMapping(value = "/aiExportRecord")
   @ResponseBody
   public Map<String,Object> aiExportRecord(IpRecords records, QueryRequest queryRequest){
      return super.selectByPageNumSize(queryRequest,() -> this.bigEmpIrecords.getAiIpRecords(records));
   }

   /**
    * 获取所有的导出记录  不分页
    * **/
   @RequestMapping(value = "/exportRecordName")
   @ResponseBody
   public List<IpRecords> exportRecordName(){
       return this.bigEmpIrecords.getIpRecords(new IpRecords());
   }

   /**更新导出记录的状态信息 包括结算 忽略 恢复和 意向状态**/
   @RequestMapping(value = "/updateExportbatchRecord")
   @ResponseBody
   public ResponseBo updateExportbatchRecord(IpRecords records){
      return bigEmpIrecords.updateExportBatchCustomer(records);
   }

   /**导出用户**/
   @RequestMapping("/exportBigEmpExcel")
   @ResponseBody
   public ResponseBo exportBigEmpExcel(Long kid){
      try {
         MyUser myUser = this.getCurrentUser();
         IpRecords records=  bigEmpIrecords.getexportBatchCustomer(kid);
         List<BigEmp> list = bigEmpServices.exportBigEmpInfo(records.getcIpIds(),myUser);
         IpRecords ipRecords = new IpRecords();
         ipRecords.setcIpId(Integer.valueOf(kid+""));
         ipRecords.setcIpStatus("1");
         ResponseBo responseBo = FileUtils.createExcelByPOIKit("客户资料表", list, BigEmp.class);
         bigEmpIrecords.updateExportBatchCustomer(ipRecords);
         return responseBo;
      } catch (Exception e) {
         e.printStackTrace();
         return ResponseBo.error("导出Excel失败，请联系网站管理员！");
      }
   }


}
